<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class NotificationModel extends CI_Model 
{ 
	public $table = 'notifications';
  	public $primary = 'notification_id';
  
  	function add($data)
  	{
  		$this->db->insert($this->table, $data);
  	}
  	
  	function update($id, $data)
  	{
    	$this->db->where($this->primary, $id);
    	return $this->db->update($this->table, $data);
  	}
	public function delete($id)
  	{
    	$this->db->where($this->primary, $id);
    	return $this->db->delete($this->table);
  	}
    public function cnt() 
   	{
       	return $this->db->count_all($this->table);
   	}
  	public function getNotifications($limit, $start) 
    {
	    $this->db->limit($limit, $start);
	    $this->db->order_by($this->primary, 'desc');
	    $query = $this->db->get($this->table);
	    
	    return $query->result_array();
    }  
//    public function getAllNotifications()
//    {
//      $query = $this->db->query("SELECT * FROM  `notifications` 
//   								WHERE 1");
//  	  return $query->result_array();
//    } 
    
  	function getNotificationById($id)
  	{
    	$query = $this->db->query("SELECT * FROM  {$this->table} 
    							WHERE {$this->primary} = {$id}");
   		return $query->row_array();
  	}
}